<?php
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/Lib/Base.php';
require_once __DIR__ . '/funcs.php';

checkLogin();

// 获取权限列表
$funcs = getFuncs($_SESSION['admin_group']);

$my_info = $DB->get('admin_user', '*', ['id'=>$_SESSION['admin_id']]);
$my_group = $DB->get('admin_groups', ['name'], ['id'=>$_SESSION['admin_group']]);

?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>管理后台 - 首页</title>
	<!-- Tell the browser to be responsive to screen width -->
	<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
	<!-- Bootstrap 3.3.7 -->
	<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
	<!-- Font Awesome -->
	<link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
	<!-- Ionicons -->
	<link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
	<!-- Theme style -->
	<link rel="stylesheet" href="dist/css/AdminLTE.min.css">
	<!-- AdminLTE Skins. Choose a skin from the css/skins
		 folder instead of downloading all of them to reduce the load. -->
	<link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
</head>
<body class="hold-transition skin-blue sidebar-mini" style="overflow-y:hidden;">
<div class="wrapper">

	<header class="main-header">
		<!-- Logo -->
		<a href="index.php" class="logo">管理后台</a>
		<!-- Header Navbar: style can be found in header.less -->
		<nav id="topnav" class="navbar navbar-static-top">
			<!-- Sidebar toggle button-->
			<a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
				<span class="sr-only">Toggle navigation</span>
			</a>
			<button class="btn btn-success" style="display:inline-block;margin-left:10px;margin-top:8px;" onclick="document.getElementById('main_frame').contentWindow.location.reload(true);">
				<i class="fa fa-refresh"></i> 刷新本页
			</button>

			<div class="navbar-custom-menu">
				<ul class="nav navbar-nav">
					<!-- User Account: style can be found in dropdown.less -->
					<li class="dropdown user user-menu">
						<a href="#" class="dropdown-toggle" data-toggle="dropdown">
							<img src="dist/img/user2-160x160.jpg" class="user-image" alt="User Image">
                            <span class="hidden-xs">
                                您好,
                                <span style="font-weight:bold;font-size:16px;display:inline-block;padding-left:5px;padding-right:5px;"><?php echo $my_info['username']; ?></span>
                                [<?php echo $my_group['name']; ?>]
                            </span>
						</a>
						<ul class="dropdown-menu">
							<!-- User image -->
							<li class="user-header">
								<img src="dist/img/user2-160x160.jpg" class="img-circle" alt="User Image">

								<p>
                                    <?php echo $my_info['username']; ?> - <?php echo $my_group['name']; ?>
								</p>
							</li>
							<!-- Menu Footer-->
							<li class="user-footer">
								<div class="pull-left">
								</div>
								<div class="pull-right">
									<a href="logout.php" class="btn btn-default btn-flat">安全退出</a>
								</div>
							</li>
						</ul>
					</li>
					<!-- Control Sidebar Toggle Button -->
					<li>
						<a href="logout.php"><i class="fa  fa-sign-out"> 安全退出</i></a>
					</li>
				</ul>
			</div>
		</nav>
	</header>
	<!-- Left side column. contains the logo and sidebar -->
	<aside class="main-sidebar">
		<!-- sidebar: style can be found in sidebar.less -->
		<section class="sidebar">
			<!-- sidebar menu: : style can be found in sidebar.less -->
			<ul id="allmenu" class="sidebar-menu" data-widget="tree">
				<li><a href="index.php" url="dashboard.php"><i class="fa fa-dashboard"></i> <span>控制台首页</span></a></li>

				<?php if(count(array_intersect([1,6,8,10], $funcs)) > 0) { ?>
                    <li class="treeview">
                        <a href="javascript:;">
                            <i class="fa fa-magic"></i> <span>游戏管理</span>
                            <span class="pull-right-container">
                          <i class="fa fa-angle-left pull-right"></i>
                        </span>
                        </a>
                        <ul class="treeview-menu">
                            <?php if(in_array(12,$funcs)) { ?><li><a href="javascript:;" url="game_user.php"><i class="fa fa-street-view"></i> 用户管理</a></li><?php } ?>
                            <?php if(in_array(8,$funcs)) { ?><li><a href="javascript:;" url="game_config.php"><i class="fa fa-street-view"></i> 参数配置</a></li><?php } ?>
<!--							--><?php //if(in_array(1,$funcs)) { ?><!--<li><a href="javascript:;" url="game_task.php"><i class="fa fa-street-view"></i> 任务管理</a></li>--><?php //} ?>
                            <?php if(in_array(6,$funcs)) { ?><li><a href="javascript:;" url="game_banner.php"><i class="fa fa-street-view"></i> Banner管理</a></li><?php } ?>
                            <?php if(in_array(10,$funcs)) { ?><li><a href="javascript:;" url="game_sign.php"><i class="fa fa-street-view"></i> 签到配置</a></li><?php } ?>
                            <?php if(in_array(6,$funcs)) { ?><li><a href="javascript:;" url="game_coupon.php"><i class="fa fa-street-view"></i> 优惠券管理</a></li><?php } ?>
                            <?php if(in_array(6,$funcs)) { ?><li><a href="javascript:;" url="game_icon.php"><i class="fa fa-street-view"></i> icon管理</a></li><?php } ?>
                        </ul>
                    </li>
				<?php } ?>

                <?php if(count(array_intersect([1], $funcs)) > 0) { ?>
                    <li class="treeview">
                        <a href="javascript:;">
                            <i class="fa fa-magic"></i> <span>任务管理</span>
                            <span class="pull-right-container">
                          <i class="fa fa-angle-left pull-right"></i>
                        </span>
                        </a>
                        <ul class="treeview-menu">
                            <?php if(in_array(1,$funcs)) { ?><li><a href="javascript:;" url="game_task.php?type=1"><i class="fa fa-street-view"></i> 普通任务</a></li><?php } ?>
                            <?php if(in_array(1,$funcs)) { ?><li><a href="javascript:;" url="game_task.php?type=2"><i class="fa fa-street-view"></i> 餐点任务</a></li><?php } ?>
                            <?php if(in_array(1,$funcs)) { ?><li><a href="javascript:;" url="game_task.php?type=3"><i class="fa fa-street-view"></i> 升级任务</a></li><?php } ?>
                            <?php if(in_array(1,$funcs)) { ?><li><a href="javascript:;" url="game_task.php?type=4"><i class="fa fa-street-view"></i> 浏览任务</a></li><?php } ?>
                        </ul>
                    </li>
                <?php } ?>

                <?php if(count(array_intersect([3,5], $funcs)) > 0) { ?>
                    <li class="treeview">
                        <a href="javascript:;">
                            <i class="fa fa-magic"></i> <span>兑换管理</span>
                            <span class="pull-right-container">
                          <i class="fa fa-angle-left pull-right"></i>
                        </span>
                        </a>
                        <ul class="treeview-menu">
                            <?php if(in_array(3,$funcs)) { ?><li><a href="javascript:;" url="exchange_type.php"><i class="fa fa-street-view"></i> 兑换类型</a></li><?php } ?>
                            <?php if(in_array(3,$funcs)) { ?><li><a href="javascript:;" url="exchange_children.php"><i class="fa fa-street-view"></i> 兑换子类</a></li><?php } ?>
                            <?php if(in_array(3,$funcs)) { ?><li><a href="javascript:;" url="exchange_item.php"><i class="fa fa-street-view"></i> 兑换商品</a></li><?php } ?>
                            <?php if(in_array(5,$funcs)) { ?><li><a href="javascript:;" url="exchange_record.php"><i class="fa fa-street-view"></i> 兑换记录</a></li><?php } ?>
                        </ul>
                    </li>
                <?php } ?>

                <?php if(count(array_intersect([63], $funcs)) > 0) { ?>
                    <li class="treeview">
                        <a href="javascript:;">
                            <i class="fa fa-magic"></i> <span>活跃度排行榜管理</span>
                            <span class="pull-right-container">
                        <i class="fa fa-angle-left pull-right"></i>
                        </span>
                        </a>
                        <ul class="treeview-menu">
                            <?php if(in_array(63,$funcs)) { ?><li><a href="javascript:;" url="active_rank_banner.php"><i class="fa fa-street-view"></i> Banner管理</a></li><?php } ?>
                            <?php if(in_array(65,$funcs)) { ?><li><a href="javascript:;" url="active_rank_strategy.php"><i class="fa fa-street-view"></i> 活动攻略</a></li><?php } ?>
                            <?php if(in_array(67,$funcs)) { ?><li><a href="javascript:;" url="active_rank_reward.php"><i class="fa fa-street-view"></i> 奖励管理</a></li><?php } ?>
                        </ul>
                    </li>
                <?php } ?>

                <?php if(count(array_intersect([70], $funcs)) > 0) { ?>
                    <li class="treeview">
                        <a href="javascript:;">
                            <i class="fa fa-magic"></i> <span>红包管理</span>
                            <span class="pull-right-container">
                        <i class="fa fa-angle-left pull-right"></i>
                        </span>
                        </a>
                        <ul class="treeview-menu">
                            <?php if(in_array(70,$funcs)) { ?><li><a href="javascript:;" url="red_packet_list.php"><i class="fa fa-street-view"></i> 红包奖励</a></li><?php } ?>
                            <?php if(in_array(72,$funcs)) { ?><li><a href="javascript:;" url="red_packet_dressup.php"><i class="fa fa-street-view"></i> 装扮配置</a></li><?php } ?>
                            <?php if(in_array(74,$funcs)) { ?><li><a href="javascript:;" url="red_packet_coupon.php"><i class="fa fa-street-view"></i> 优惠券配置</a></li><?php } ?>
                        </ul>
                    </li>
                <?php } ?>

                <?php if(count(array_intersect([80], $funcs)) > 0) { ?>
                    <li class="treeview">
                        <a href="javascript:;">
                            <i class="fa fa-magic"></i> <span>小游戏管理</span>
                            <span class="pull-right-container">
                        <i class="fa fa-angle-left pull-right"></i>
                        </span>
                        </a>
                        <ul class="treeview-menu">
                            <?php if(in_array(80,$funcs)) { ?><li><a href="javascript:;" url="small_game_list.php"><i class="fa fa-street-view"></i> 游戏管理</a></li><?php } ?>
                            <?php if(in_array(82,$funcs)) { ?><li><a href="javascript:;" url="lear_jump.php"><i class="fa fa-street-view"></i> 蹦蹦跳奖励</a></li><?php } ?>
                            <?php if(in_array(84,$funcs)) { ?><li><a href="javascript:;" url="lear_jump_coupon.php"><i class="fa fa-street-view"></i> 优惠券配置</a></li><?php } ?>
                        </ul>
                    </li>
                <?php } ?>

				<?php if(in_array(13,$funcs)) { ?>
                <li>
                    <a class="first_menu" href="javascript:;" url="log.php">
                        <i class="fa fa-gears"></i> <span>操作日志</span>
                    </a>
                </li>
                <?php } ?>

                <?php if(in_array(62,$funcs)) { ?>
                <li>
                    <a class="first_menu" href="javascript:;" url="audit.php">
                        <i class="fa fa-cloud-upload"></i> <span>审核修改</span>
                    </a>
                </li>
                <?php } ?>

				<?php if(count(array_intersect([9900], $funcs)) > 0) { ?>
                    <li class="treeview">
                        <a href="javascript:;">
                            <i class="fa fa-bomb"></i> <span>系统管理</span>
                            <span class="pull-right-container">
                          <i class="fa fa-angle-left pull-right"></i>
                        </span>
                        </a>
                        <ul class="treeview-menu">
							<?php if(in_array(9900,$funcs)) { ?><li><a href="javascript:;" url="super_user.php"><i class="fa fa-cogs"></i> 管理员列表</a></li><?php } ?>
	                        <?php if(in_array(9901,$funcs)) { ?><li><a href="javascript:;" url="super_group.php"><i class="fa fa-cogs"></i> 分组管理</a></li><?php } ?>
                        </ul>
                    </li>
				<?php } ?>
			</ul>
		</section>
		<!-- /.sidebar -->
	</aside>

	<!-- Content Wrapper. Contains page content -->
	<div class="content-wrapper">

        <iframe id="main_frame" src="dashboard.php" style="width:100%;border:0;margin:0;padding:0;border-bottom:1px solid #eee;"></iframe>

	</div>
</div>
<!-- ./wrapper -->

<!-- jQuery 3 -->
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="bower_components/jquery-ui/jquery-ui.min.js"></script>
<script src="js/vue.min.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
    $.widget.bridge('uibutton', $.ui.button);
    var height = $(window).height();
    var top_height = $('#topnav').height();
    $('#main_frame').css('height', height-top_height);

    $('a.first_menu').click(function() {
        $('.treeview').removeClass('active');
        $('.treeview-menu li').removeClass('active');
        $('.first_menu').parent().removeClass('active');
        $(this).parent().addClass('active');
        var url = $(this).attr('url');
        if(!url) url = '404.php';
        $('#main_frame').attr('src', url);
    });

    $('.treeview-menu li a').click(function() {
        $('.treeview').removeClass('active');
        $(this).parent().parent().parent().addClass('active');
        $('.treeview-menu li').removeClass('active');
        $('.first_menu').parent().removeClass('active');
        $(this).parent().addClass('active');
        var url = $(this).attr('url');
        if(!url) url = '404.php';
        $('#main_frame').attr('src', url);
    });
</script>
<!-- Bootstrap 3.3.7 -->
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- Morris.js charts -->
<script src="bower_components/raphael/raphael.min.js"></script>
<script src="bower_components/morris.js/morris.min.js"></script>
<!-- Slimscroll -->
<script src="bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/adminlte.min.js"></script>
</body>
</html>
